﻿using System;
using System.Reflection;
using AdAggregator.Attribute;

namespace AdAggregator.Util
{
    public static class EnumUtils
    {
        public static String GetEnumName(this Enum value)
        {
            var result = value.ToString();
            var type = value.GetType();
            var fi = type.GetField(value.ToString());
            var attr = fi.GetCustomAttribute<EnumName>();
            if (attr != null)
            {
                result = attr.Name;
            }
            return result;
        }
    }
}